import { createRouter, createWebHistory } from 'vue-router'
import { store } from '@/store'
import routes from './routes'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import { createPermissionGuard } from '@/router/guard/permissionGuard'

export const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from) => {
  Nprogress.start()
  // 监控页面切换，增加tab
  store.dispatch('page/openPage', to).catch()
})

router.afterEach((to, from) => {
  Nprogress.done()
})

export function setupRouter(app) {
  createPermissionGuard(router)
  app.use(router)
}
